<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.wxtf.platform.plugins.user.*"%>
<%@page import="com.wxtf.platform.tools.FormatUtil"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
	UserBean user = (UserBean)request.getSession().getAttribute("userBean");
	
	String _db = user.getDbType();
	String[] ids = user.getCurSubOrgId().split(",");
	
	Map<String,List<Map<String, String>>> dicMap = user.getDicMap();
	List<Map<String, String>> list = null;
	String tmadkind = "";//药具种类
	String tbe_employment_forms = "";//用工形式
	String tbe_nation = "";//民族
	String tbe_marital_status = "";//婚姻状态
	String tbe_marital_condition = "";//婚姻状况
	String tbe_qualification = "";//学历
	String tbe_status = "";//员工状态
	String tbe_ba_status = "";//生育能力状态
	String tbe_birth_control_measures = "";//节育措施
	String tbe_sex = "";//性别
	String nowdate = FormatUtil.getCurentDate();
	list = dicMap.get("101");
	if(null != list && list.size() > 0){
		for(Map<String, String> map: list){
			tbe_employment_forms += "<option value=\"" + map.get("tmgd_id")+"\">" + map.get("tmgd_name") + "</option>";
		}
	}
	list = null;
	list = dicMap.get("5");
	if(null != list && list.size() > 0){
		for(Map<String, String> map: list){
			tbe_nation += "<option value=\"" + map.get("tmgd_id")+"\">" + map.get("tmgd_name") + "</option>";
		}
	}
	list = null;
	list = dicMap.get("27");
	if(null != list && list.size() > 0){
		for(Map<String, String> map: list){
			tbe_marital_status += "<option value=\"" + map.get("tmgd_id")+"\">" + map.get("tmgd_name") + "</option>";
		}
	}
	list = null;
	list = dicMap.get("7");
	if(null != list && list.size() > 0){
		for(Map<String, String> map: list){
			tbe_marital_condition += "<option value=\"" + map.get("tmgd_id")+"\">" + map.get("tmgd_name") + "</option>";
		}
	}
	list = null;
	list = dicMap.get("6");
	tbe_sex += "<option value=\"\">--请选择--</option>";
	if(null != list && list.size() > 0){
		for(Map<String, String> map: list){
			tbe_sex += "<option value=\"" + map.get("tmgd_id")+"\">" + map.get("tmgd_name") + "</option>";
		}
	}
	list = null;
	list = dicMap.get("8");
	if(null != list && list.size() > 0){
		for(Map<String, String> map: list){
			tbe_qualification += "<option value=\"" + map.get("tmgd_id")+"\">" + map.get("tmgd_name") + "</option>";
		}
	}
	list = null;
	list = dicMap.get("102");
	if(null != list && list.size() > 0){
		for(Map<String, String> map: list){
			tbe_status += "<option value=\"" + map.get("tmgd_id")+"\">" + map.get("tmgd_name") + "</option>";
		}
	}
	list = null;
	list = dicMap.get("103");
	if(null != list && list.size() > 0){
		for(Map<String, String> map: list){
			tbe_ba_status += "<option value=\"" + map.get("tmgd_id")+"\">" + map.get("tmgd_name") + "</option>";
		}
	}
	list = null;
	list = dicMap.get("104");
	if(null != list && list.size() > 0){
		for(Map<String, String> map: list){
			tbe_birth_control_measures += "<option value=\"" + map.get("tmgd_id")+"\">" + map.get("tmgd_name") + "</option>";
		}
	}
	
	list = dicMap.get("105");
	tmadkind += "<option value=\"\">--请选择--</option>";
	if(null != list && list.size() > 0){
		String str;
		for(Map<String, String> map: list){
			str = map.get("tmgd_id");
			if(!"105-3".equals(str) && !"105-5".equals(str) && !"105-4".equals(str)  && !"105-1".equals(str) ){
				tmadkind += "<option value=\"" + str+"\">" + map.get("tmgd_name") + "</option>";
			}
		}
	}
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<base href="<%=basePath%>"/>
		<meta http-equiv="pragma" content="no-cache"/>
		<meta http-equiv="cache-control" content="no-cache"/>
		<meta http-equiv="expires" content="0"/>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge"/>

		<link type="text/css" rel="stylesheet" href="ligerUI/skins/Aqua/css/ligerui-all.css" />
		<link type="text/css" rel="stylesheet" href="ligerUI/skins/<%=user.getUserCss()%>/css/ligerui-all.css" />
		<link type="text/css" rel="stylesheet" href="ligerUI/skins/ligerui-icons.css" />
		<link type="text/css" rel="stylesheet" href="resource/css/style.css" />

		<script type="text/javascript" src="js/jquery/jquery-1.7.2.js"></script>
		<script type="text/javascript" src="ligerUI/js/core/base.js"></script>
		<script type="text/javascript" src="ligerUI/js/ligerui.min.js"></script>
		<script type="text/javascript" src="js/common.js"></script>
		<script type="text/javascript" src="js/validata.js"></script>

		<script type="text/javascript" src="ligerUI/js/plugins/ligerGrid.js"></script>
		<script type="text/javascript" src="ligerUI/js/plugins/ligerDialog.js"></script>
		<script type="text/javascript" src="ligerUI/js/plugins/ligerTree.js"></script>
		<script type="text/javascript" src="ligerUI/js/plugins/ligerForm.js"></script>
		<script type="text/javascript" src="ligerUI/js/plugins/ligerComboBox.js"></script>
		<script type="text/javascript" src="ligerUI/js/plugins/ligerDateEditor.js"></script>
	    <script src="ligerUI/js/plugins/ligerTextBox.js" type="text/javascript"></script>
	    <script src="ligerUI/js/plugins/ligerSpinner.js" type="text/javascript"></script>
<script type="text/javascript">
var _db = '<%=_db%>';
var _jsonEmp = {};
_jsonObj.classname = "com.wxtf.platform.main.contraceptives.TmaProvide";
_jsonObj.methodname = "queryPage";
_jsonEmp.classname = "com.wxtf.platform.main.contraceptives.TmaProvide";
_jsonEmp.methodname = "queryPer";
var win;//药具登记
var win1;//药具登记查看
var empwin;//员工win
var manager;
var empgrid;
var reg = /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/;
var isCopy = false;
$(function(){
	if(<%=ids.length%> > 1){
		$("body").html('当前机构不允许发放！请冲重新登录切换机构。');
		return;
	}
	_jsonObj.logicdata = getForm("query_form");
	manager = $("#mgrid").ligerGrid({
		url: _url, parms: _jsonObj, width: '100%', height: '100%',delayLoad: true,
		usePager: true, rownumbers: true, checkbox: true, alternatingRow: true,async:false,
		columns: [
			{ display: 'tmapm_id', name: 'tmapm_id', hide: true,width:1 },
			{ display: 'tbe_id', name: 'tbe_id', hide: true,width:1 },
			{ display: 'org_id', name: 'org_id', hide: true,width:1 },
			{ display: '发放编号', name: 'tmapm_code',width:150, align:'left',
				render: function(record, index, value, oth){
					if(record.reserve2 == '1'){
						return " <a href='javascript:search(" + JSON.stringify(record) + ")'>"+value+"</a>";
					}else{
						return " <a href='javascript:edit(" + JSON.stringify(record) + ")'>"+value+"</a>";
					}
				} 
			},
			{ display: '姓名', name: 'tbe_name',width:100, align:'left'},
			{ display: '身份证号', name: 'tbe_idcard',hide: true,width:1},
			{ display: '员工编号', name: 'tbe_work_permit', hide: true,width:1 },
			{ display: '住址', name: 'tbe_address', hide: true,width:1 },
			{ display: '性别', name: 'tbe_sex', width: 60, align: 'left' },
			{ display: '年龄', name: 'tbe_age', hide: true,width:1 },
			{ display: '文化程度', name: 'tbe_qualification', hide: true,width:1 },
			{ display: '配偶姓名', name: 'tbfi_spouse_name', hide: true,width:1 },
			{ display: '子女数', name: 'tbfi_children_num', width: 60, align: 'left' },
			{ display: '药具名称', name: 'tmad_name', width: 150, align: 'left' },
			{ display: '发放形式', name: 'tmapm_style', width: 80, align: 'left' ,
				render: function(record, index, value, oth){
					var str="";
					if(value == 0){
						str = "发放";
					}else{
						str = "领用";
					}
					return str;
				}
			},
			{ display: '发放人', name: 'tmapm_person', width: 100, align: 'left' },
			{ display: '发放时间', name: 'tmapm_time', width: 100, align: 'left' },
			{ display: '用药开始时间', name: 'tmapm_begin_time', width: 100, align: 'left' },
			{ display: '用药理由', name: 'tmapm_reason', width: 100, align: 'left' },
			{ display: '曾经用过何药具', name: 'tmapm_last_medicine', width: 150, align: 'left' },
			{ display: '有无失败史', name: 'tmapm_is_fail', width: 100, align: 'left' ,
				render: function(record, index, value, oth){
					var str="";
					if(value == 1){
						str = "有";
					}else{
						str = "无";
					}
					return str;
				}
			},
			{ display: '失败原因', name: 'tmapm_fail_reason', width: 100, align: 'left' },
			{ display: '备注', name: 'tmapm_memo', width:  1, hide:true },
			{ display: 'reserve1', name: 'reserve1', width:  1, hide:true },
			{ display: 'reserve2', name: 'reserve2', width:  1, hide:true },
			{ display: 'reserve3', name: 'reserve3', width:  1, hide:true },
			{ display: 'reserve4', name: 'reserve4', width:  1, hide:true },
			{ display: 'reserve5', name: 'reserve5', width:  1, hide:true },
			{ display: '录入人', name: 'create_by', width:  1, hide:true },
			{ display: '录入时间', name: 'create_time', width:  1, hide:true },
			{ display: '最后修改人', name: 'last_modify_by', width:  1, hide:true },
			{ display: '最后修改时间', name: 'last_modify_time', width: 1, hide:true },
			{ display: '编辑', name:'edit',width:60,render: function(record, index, value, oth){
					if(record.reserve2 == '1'){
						return "<img src='ligerUI/skins/icons/search.gif' onclick='search(" + JSON.stringify(record) + ")'></img>";
					}else{
						return "<img src='ligerUI/skins/icons/edit.gif' onclick='edit(" + JSON.stringify(record) + ")'></img>";
					}
				}
			}
			
		],
		toolbar: {
			items: [
				{ text: '新建', click: function(){ addData(); }, icon: 'add' },
				{ line: true },
				{ text: '删除', click: function(){ delData(); }, icon: 'delete'}
			]
		}
		
	}); 
	$("#mform #tmapm_begin_time").ligerDateEditor({ format: "yyyy-MM-dd", width:182});
	$("#mform #tmapm_time").ligerDateEditor({ format: "yyyy-MM-dd", width:182});
	_jsonEmp.logicdata = getForm("query_pre");
	empgrid = $("#emp-grid").ligerGrid({
		url: _url,parms: _jsonEmp, width: 775, height: 265, delayLoad: true,
		usePager: true, async:false, rownumbers: true, checkbox: true,
		columns: [
			{ display: 'tbe_id', name: 'tbe_id', hide: true,width:1 },
			{ display: 'org_id', name: 'org_id', hide: true,width:1 },
			{ display: '机构名称', name: 'reserve1', width:150, align:'left' },
			{ display: '姓名', name: 'tbe_name', width: 100, align: 'left' },
			{ display: '身份证号', name: 'tbe_idcard', width: 150, align: 'left' },
			{ display: '职工证号', name: 'tbe_work_permit', width: 1, hide:true },
			{ display: '用工形式', name: 'tbe_employment_forms', width:  1, hide:true },
			{ display: '曾用名', name: 'tbe_former_name', width:  1, hide:true  },
			{ display: '拼音码', name: 'tbe_spell_code', width:  1, hide:true  },
			{ display: '性别', name: 'tbe_sex', width: 60, align: 'left' },
			{ display: '出生日期', name: 'tbe_birthday', width:  1, hide:true },
			{ display: '年龄', name: 'tbe_age', width:  1, hide:true },
			{ display: '籍贯', name: 'tbe_native_palce', width:  1, hide:true },
			{ display: '民族', name: 'tbe_nation', width:  1, hide:true },
			{ display: '出生地', name: 'tbe_birthplace', width:  1, hide:true },
			{ display: '入厂时间', name: 'tbe_join_time', width:  1, hide:true },
			{ display: '工龄', name: 'tbe_seniority', width:  1, hide:true },
			{ display: '手机', name: 'tbe_mobile', width:  1, hide:true },
			{ display: '家庭电话', name: 'tbe_family_phone',width:  1, hide:true },
			{ display: '家庭住址', name: 'tbe_address', width: 100, align: 'left' },
			{ display: '婚姻状态', name: 'tbe_marital_status', width:  1, hide:true},
			{ display: '婚姻状况', name: 'tbe_marital_condition', width:  1, hide:true},
			{ display: '结婚时间', name: 'tbe_married_time', width:  1, hide:true },
			{ display: '结婚证号', name: 'tbe_marriage_certificate', width:  1, hide:true },
			{ display: '政治面貌', name: 'tbe_political_status', width:  1, hide:true },
			{ display: '学历', name: 'tbe_qualification', width:  1, hide:true },
			{ display: '毕业学校', name: 'tbe_graduate_college', width:  1, hide:true },
			{ display: '所学专业', name: 'tbe_major', width:  1, hide:true },
			{ display: '工作时间', name: 'tbe_work_area', width:  1, hide:true },
			{ display: '职务', name: 'tbe_position', width:  1, hide:true },
			{ display: '是否允许再生育', name: 'tbe_is_again_birth', width:  1, hide:true },
			{ display: '是否不孕症（绝经）', name: 'tbe_is_barrenness', width:  1, hide:true },
			{ display: '是否晚婚', name: 'tbe_is_late_marriage', width:  1, hide:true },
			{ display: '是否晚育', name: 'tbe_is_late_birth', width:  1, hide:true },
			{ display: '员工状态', name: 'tbe_status', width:  1, hide:true },
			{ display: '生育能力状态', name: 'tbe_ba_status', width:  1, hide:true },
			{ display: '节育措施', name: 'tbe_birth_control_measures', width:  1, hide:true },
			{ display: '设为重点时间', name: 'tbe_es_time', width:  1, hide:true },
			{ display: '是否重点服务对象', name: 'tbe_is_es', width:  1, hide:true },
			{ display: '重点理由', name: 'tbe_es_reason', width:  1, hide:true },
			{ display: '子女情况', name: 'tbe_children_status', width:  1, hide:true },
			{ display: '排序号', name: 'tbe_order', width:  1, hide:true },
			{ display: '备注', name: 'tbe_memo', width:  1, hide:true },
			{ display: '子女数', name: 'tbfi_children_num', width: 50, align: 'left' },
			{ display: '配偶姓名', name: 'tbfi_spouse_name', width: 100, align: 'left' }
		],
		onCheckRow: function(checked, rowdata, rowindex) {
		    for (var rowid in this.records)
		        this.unselect(rowid); 
		    this.select(rowindex);
		}
	});
});
/*
 * 登记条件查询
 */
function serch1(){
	$("#query_form #types").val("serch1");
	_jsonObj.methodname = "queryPage";
	_jsonObj.logicdata = getForm("query_form");  
	manager.loadData();
}
/*
 * 复制历史
 */
function copyHis(){
	if(isCopy){
		_jsonObj.methodname = "queryPage";
		_jsonObj.logicdata = getForm("query_form"); 
		$("#searbtn1").removeAttr("disabled");
		$("#copybtn").val("复制历史");
		$("#plbtn").hide();
		
	}else{
		_jsonObj.methodname = "copy";
		$("#searbtn1").attr("disabled","disabled");
		$("#copybtn").val("返回");
		$("#plbtn").show();
	}
	manager.loadData();
	if(!isCopy){
		if(manager.getData().length == 0){
			warningTip('上月没有可复制的记录。');
		}
	}
	isCopy = !isCopy;
}
/*
 * 人员条件查询
 */
function serchPer(){
	$("#query_pre #types").val("serch1");
	_jsonEmp.methodname = "queryPer";
	_jsonEmp.logicdata = getForm("query_pre");  
	empgrid.loadData();
}
/*
 * 条件重置
 */
function serReset(){
	document.getElementById('query_form').reset();
}

/*
 * 表格刷新
 */
function reload(){
	if(isCopy){
		_jsonObj.methodname = "copy";
	}else{
		_jsonObj.methodname = "queryPage";
		_jsonObj.logicdata = getForm("query_form");
	}
	manager.loadData();
}

/*
 * ajax成功回调
 */
function ajaxCallbackSuccFunc(data, textStatus){
	if(data.result){
		win.hide();
		succMsgTip(data.resultrecord);
		reload();
	}else{
		warningTip(data.resultrecord);
	}
}

/*
 * ajax失败回调
 */
function ajaxCallbackErrorFunc(data, textStatus){
	succMsgTip(data.resultrecord);
}

/*
 * 获取列表选中的药具ID
 */
function getIds(){
	var array = manager.getSelecteds();
	if(array.length == 0){
		return "";
	} else {
		var text = "";
		for(var i=0; i<array.length; i++){
			if(array[i].reserve2 == '1'){
				//warningTip("发放编号："+array[i].tmapm_code+"已提交，不能删除。");
				//return "-99";
			}
			text += array[i].tmapm_id + ",";
		}
		return text.substring(0, text.length - 1);
	}
}

/*
 * 新建药具发放登记
 */
function addData(){
	document.getElementById('mform').reset();
	$("#mform #tmapm_id").val('');
	$("#mform #tbe_id").val('');
	$("#mform #reserve2").val('');
	if(win == null){
		win = initWindowByDivM('mdiv', '药具发放登记', 860, 400 ,save,closeMwin,save1);
	}else{
		win.show();
	}
	$("#mform #months").removeAttr("disabled","disabled");
}
/*
 * 批量药具发放暂存
 */
function copyAdd(){
	if(isCopy){
		var array = manager.getSelecteds();
		if(array.length > 0){
			_jsonObj.methodname = "copySave";
			_jsonObj.logicdata = JSON.stringify(array);
			callserver(_jsonObj, function(data, textStatus){
				succMsgTip(data.resultrecord);
				reload();
			}, ajaxCallbackErrorFunc);
		}else{
			warningTip("请至少选择一个发放记录进行操作!");
		}
	}else{
		warningTip("请先复制历史再批量发放!");
	}
	
}
/*
 * 修改发放登记
 */
function edit(row){
	document.getElementById('mform').reset();
	loadForm("mform", row);
	if(win == null){
		win = initWindowByDivM('mdiv', '新建药具发放记录', 860, 400 ,save, closeMwin ,save1);
	}else{
		win.show();
	}
	selTamName(row.tmad_kind,'mform');
	$("#mform #tmad_id").val(row.tmad_id1);
	tmaNameChange(row.tmad_id1,'mform');
	$("#mform #tmapd_num").val(row.tmapd_num);
	var s1 = $("#mform #tmad_price").val();
	if(reg.test(s1) && reg.test(row.tmapd_num)){
		$("#mform #tmapd_zj").val(parseInt(row.tmapd_num)*(parseFloat(s1)*1000)/1000);
		
	}else{
		$("#mform #tmapd_zj").val('');
	}
	$("#mform #months").attr("disabled","disabled");
}
/*
 * 查看发放登记
 */
function search(row){
	document.getElementById('mform2').reset();
	loadForm("mform2", row);
	if(win1 == null){
		win1 = initWindowByDivM2('mdiv2', '查看药具发放记录', 860, 430 ,save, closeMwin1);
	}else{
		win1.show();
	}
	selTamName(row.tmad_kind,'mform2');
	$("#mform2 #tmad_id").val(row.tmad_id1);
	tmaNameChange(row.tmad_id1,'mform2');
	$("#mform2 #tmapd_num").val(row.tmapd_num);
	var s1 = $("#mform2 #tmad_price").val();
	if(reg.test(s1) && reg.test(row.tmapd_num)){
	
		$("#mform2 #tmapd_zj").val(parseInt(row.tmapd_num)*(parseFloat($("#mform2 #tmad_price").val())*1000)/1000);
		
	}else{
		$("#mform2 #tmapd_zj").val('');
	}
	$("#mform2 #months").attr("disabled","disabled");
}
/*
 * 选择员工
 */
function selectPer(){
	if(empwin == null){
		empwin = initWindowByDiv('empwin', '选择员工', 800, 400 ,confirmPer, closeEmpWin);
	}else{
		empwin.show();
	}
	//empgrid.set({url: _url});
	//empgrid.reRender();
}
/*
 * 初始化窗口
 */
function initWindowByDivM(target, title, width, height, func, func2 ,func3){
	return $.ligerDialog.open({
		width: width,
		height: height,
		title:title,
		modal:true,
		allowClose: true,
		target: $("#"+target),
		buttons: [{
			text: '暂存', onclick: func
		}, {
			text: '取消', onclick: func2
		},{
			text: '提交', onclick: func3
		}]
	});
}
/*
 * 初始化查看窗口
 */
function initWindowByDivM2(target, title, width, height){
	return $.ligerDialog.open({
		width: width,
		height: height,
		title:title,
		modal:true,
		allowClose: true,
		target: $("#"+target)
	});
}
/*
 * 关闭员工empwin
 */
function closeEmpWin(){
	empwin.hide();
}
/*
 * 选择员工确认
 */
function confirmPer(){
	var rows = [];
	var reserve1 = $("#mform #reserve1").val();
 	rows = empgrid.getCheckedRows();
   	if(rows.length < 1){
   		$.ligerDialog.warn('请选择人员!');
   	}else if(rows.length > 1){
   		$.ligerDialog.warn('不能选择多个人!');
   		for (var rowid in empgrid.records)
			empgrid.unselect(rowid);
   	}else{
   		document.getElementById('mform').reset();
   		$("#tbe_id").val('');
   		loadForm("mform", rows[0]);
   		$("#mform #reserve1").val(reserve1);
   		empwin.hide();
   	}
	        	
}

/*
 * 关闭药具发放登记窗口win
 */
function closeMwin(){
	win.hide();
}
/*
 * 关闭查看窗口win
 */
function closeMwin1(){
	win1.hide();
}
/*
 * 新建/修改药具信息
 */
function save(){
	if(checkForm()){
		var tmapm_id = $("#mform #tmapm_id").val();
		_jsonObj.logicdata = getForm("mform");
		if(tmapm_id == ''){
			_jsonObj.methodname = "save";
			callserver(_jsonObj, ajaxCallbackSuccFunc, ajaxCallbackErrorFunc);
		} else {
			_jsonObj.methodname = "update";
			callserver(_jsonObj, ajaxCallbackSuccFunc, ajaxCallbackErrorFunc);
		}
	}
}
/*
 * 提交
 */
function save1(){
	if(checkForm()){
		var tmapm_id = $("#mform #tmapm_id").val();
		var reserve2 = $("#mform #reserve2").val();
		$.ligerDialog.confirm('提交后会生成出库和随访并且该记录不能修改，确定提交吗？', function (d)
	   	{
		     if(d){
		     	$("#mform #reserve2").val('1');
				_jsonObj.logicdata = getForm("mform");
				if(tmapm_id == ''){
					_jsonObj.methodname = "save";
					callserver(_jsonObj, ajaxCallbackSuccFunc, ajaxCallbackErrorFunc);
				} else {
					_jsonObj.methodname = "update";
					callserver(_jsonObj, ajaxCallbackSuccFunc, ajaxCallbackErrorFunc);
				}
		     }else{
		     	return;
		     }
		});
	}
}
//校验表单
function checkForm(){
	var tbe_name = $("#mform #tbe_name").val().trim();
	if(tbe_name == ''){
		warningTip("员工姓名：不能为空");
		return false;
	}
	if(!checkIsString(tbe_name)){
		warningTip("员工姓名：必须为字母、数字、下划线、中文组成");
		return false;
	}
	if(fucCheckLength(tbe_name) > 32){
		warningTip("员工姓名：不能超过32字符");
		return false;
	}
	var tmapm_time = $("#mform #tmapm_time").val().trim();
	if(tmapm_time == ''){
		warningTip("发放时间：不能为空");
		return false;
	}
	var tmapm_begin_time = $("#mform #tmapm_begin_time").val().trim();
	if(tmapm_begin_time == ''){
		warningTip("用药时间：不能为空");
		return false;
	}
	var tmapm_last_medicine = $("#mform #tmapm_last_medicine").val().trim();
	if(!checkIsString(tmapm_last_medicine)){
		warningTip("曾用药具：必须为字母、数字、下划线、中文组成");
		return false;
	}
	if(fucCheckLength(tmapm_last_medicine) > 512){
		warningTip("曾用药具：不能超过512字符");
		return false;
	}
	var tmapm_fail_reason = $("#mform #tmapm_fail_reason").val().trim();
	if(!checkIsString(tmapm_fail_reason)){
		warningTip("失败原因：必须为字母、数字、下划线、中文组成");
		return false;
	}
	if(fucCheckLength(tmapm_fail_reason) > 512){
		warningTip("失败原因：不能超过512字符");
		return false;
	}
	var tmapm_reason = $("#mform #tmapm_reason").val().trim();
	if(!checkIsString(tmapm_reason)){
		warningTip("用药理由：必须为字母、数字、下划线、中文组成");
		return false;
	}
	if(fucCheckLength(tmapm_reason) > 512){
		warningTip("用药理由：不能超过512字符");
		return false;
	}
	var tmad_id = $("#mform #tmad_id").val().trim();
	if(tmad_id == ""){
		warningTip("药具名称：不能为空");
		return false;
	}
	var tmapd_num = $("#mform #tmapd_num").val().trim();
	if(tmapd_num == ""){
		warningTip("药具数量：不能为空");
		return false;
	}
	if(!isNum(tmapd_num)){
		warningTip("药具数量：只能输入整数");
		return false;
	}
	if(fucCheckLength(tmapd_num) > 4 && tmapd_num < 0){
		warningTip("药具数量：不能大于9999且不能为负数");
		return false;
	}
	return true;
}


/*
 * 删除发放记录
 */
function delData(){
	var ids = getIds();
	if(ids == ""){
		warningTip('请至少选择一个发放记录进行操作');
		return;
	}
	if(ids == '-99'){
		return;
	}
	$.ligerDialog.confirm('确定要删除选中的数据吗？（删除不可恢复）', function (opt) { 			
		if(opt){
			_jsonObj.methodname = "delete";
	     	_jsonObj.logicdata = "[{\"ids\":\"" + ids + "\",\"isrk\":\"true\"}]";
	     	callserver(_jsonObj, function(data, textStatus){ 
		     	if(data.result){
     				succMsgTip(data.resultrecord);
					reload();
				}else{
					warningTip(data.resultrecord);
				}
	     	}, function(data, textStatus){warningTip(data.resultrecord);});
		}
	});
}

/*
 * 药具种类联动
 */
function selTamName(value,f){
	$("#"+f+" #tmad_id").html("");
	//定义药具名称
	var paramName = {
		"classname": "com.wxtf.platform.main.contraceptives.TmaProvide",
		"methodname": "selectTmaDictionary",
		"logicdata": [],
		"extenddata": []
	};
	paramName.logicdata = '[{"tmgd_id":"'+value+'"}]';
	callserver(paramName, function(data, satus){
		$("#"+f+" #tmapd_num").val("");
		$("#"+f+" #tmad_spec").val("");
		$("#"+f+" #tmad_unit").val("");
		$("#"+f+" #num").val("");
		$("#"+f+" #tmad_qgp").val("");
		$("#"+f+" #tmad_price").val("");
		$("#"+f+" #tmapd_zj").val("");
		$("#"+f+" #tmad_id").append('<option value="">--请选择--</option>');
		$.each(data, function (i, item) {
        	 $("#"+f+" #tmad_id").append('<option value="'+item.tmad_id+'">'+item.tmad_name+'</option>');
        }); 
	},function(data, satus){
		succMsgTip(data.resultrecord);
	});
}
/*
 * 药具名称联动
 */
function tmaNameChange(value,f){
	if(value == ''){
		$("#"+f+" #tmapd_num").val("");
		$("#"+f+" #tmad_spec").val("");
		$("#"+f+" #tmad_unit").val("");
		$("#"+f+" #num").val("");
		$("#"+f+" #tmad_qgp").val("");
		$("#"+f+" #tmad_price").val("");
		$("#"+f+" #tmapd_zj").val("");
		return;
	}
	//定义药具
	var paramId = {
		"classname": "com.wxtf.platform.main.contraceptives.TmaProvide",
		"methodname": "selectTmaDictionaryById",
		"logicdata": [],
		"extenddata": []
	};
	var tbeid = $("#"+f+" #tbe_id").val();
	paramId.logicdata = '[{"tmad_id":"'+value+'","tbe_id":"'+tbeid+'"}]';
	callserver(paramId, function(data, satus){
		$("#"+f+" #tmapd_num").val("");
		$("#"+f+" #tmad_spec").val(data.tmad_spec);
		$("#"+f+" #tmad_unit").val(data.tmad_unit);
		$("#"+f+" #num").val(data.num==''?'0':data.num);
		$("#"+f+" #tmad_company_name").val(data.tmad_company_name);
		$("#"+f+" #tmad_price").val(data.tmad_price);
		$("#"+f+" #tmapd_zj").val("");
		if(data.tmapm_begin_time)
		$("#"+f+" #tmapm_begin_time").val(data.tmapm_begin_time);
	},function(data, satus){
		succMsgTip(data.resultrecord);
	});
}
/*
 * 合计总价
 */
function totalPrice(){
	var a =	$("#mform #tmapd_num").val();
	var b =	$("#mform #tmad_price").val();
	if(reg.test(a) && reg.test(b)){
		$("#mform #tmapd_zj").val(parseFloat(a)*(parseFloat(b)*1000)/1000);
	}else{
		$("#mform #tmapd_zj").val('');
	}
}

//校验日期格式
function checkdata(a){
	var reg =  /^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/;
	var b = a;
	if(!reg.test(b)){
		b = "";
	}
	return b;
}
</script>
</head>
	<body>
		<form id="query_form" name="query_form">
			<input type="hidden" id="types" name="types" value="init"/>
			<table id="aaa" class="serTable">
				<tr>
					<td>领药人姓名：<input id="personname_query" name="personname_query"/></td>
					<td>药具名称：<input id="age_query" name="age_query"/></td>
					<td>发放形式：
						<select id="tmapm_style_query" name="tmapm_style_query" style=" width: 60px;" >
							<option value=""></option>
							<option value="0">发放</option>
							<option value="1">领用</option>
						</select>
					</td>
					<td><input id="searbtn1" class="btn2" value="搜索" type="button" onclick="serch1();" /></td>
					<td><input id="plbtn" class="btn2" value="批量发放" type="button" onclick="copyAdd()" style="display: none;"/></td>
				</tr>
				<tr>
					<td>发放时间开始：<input id="tmapm_time_start" name="tmapm_time_start" onkeyup="this.value=formatdata(this.value);" /></td>
					<td>发放时间结束：<input id="tmapm_time_end" name="tmapm_time_end" onkeyup="this.value=formatdata(this.value);" /></td>
					<td>是否提交：
						<select id="reserve2_query" name="reserve2_query" style=" width: 60px;" >
							<option value=""></option>
							<option value="0">否</option>
							<option value="1">是</option>
						</select>
					</td>
					<td><input class="btn2" value="重置" type="button" onclick="serReset();" /></td>
					<td><input id="copybtn" class="btn2" value="复制历史" type="button" onclick="copyHis();" /></td>
				</tr>
			</table>
		</form>
		<div id="mgrid"></div>
		<div id="mdiv" style="display: none;">
			<form id="mform" name="mform">
				<input type="hidden" id="tmapm_id" name="tmapm_id" value="" />
				<input type="hidden" id="org_id" name="org_id" value="" />
				<input type="hidden" id="tbe_id" name="tbe_id" value="" />
				<input type="hidden" id="reserve1" name="reserve1" value="1" />
				<input type="hidden" id="reserve2" name="reserve2" value="" />
				<input type="hidden" id="reserve3" name="reserve3" value="" />
				<input type="hidden" id="reserve4" name="reserve4" value="" />
				<input type="hidden" id="reserve5" name="reserve5" value="" />
				<input type="hidden" id="create_by" name="create_by" value="" />
				<input type="hidden" id="create_time" name="create_time" value="" />
				<input type="hidden" id="last_modify_by" name="last_modify_by" value="" />
				<input type="hidden" id="last_modify_time" name="last_modify_time" value="" />
				<input type="hidden" id="tmapm_memo" name="tmapm_memo" value="" />
				<input type="hidden" id="tmapm_code" name="tmapm_code" value="" />
				<input type="hidden" id="tmapd_id" name="tmapd_id" value="" />
				<input type="hidden" id="tbe_birth_control_measures" name="tbe_birth_control_measures" value="" />
				<table class="form_table">
					<tr>
						<td colspan="9" align="left">
							<div style="border-bottom: 1px solid #EBEBEB; font-weight:bold;height: 28px; line-height: 28px;margin: 0 0 5px;" >
								<img src="ligerUI/skins/icons/communication.gif"/>
								<span>员工信息</span>
								<input class="btn2" value="选择" type="button" onclick="selectPer();" />
							</div>
						</td>
					</tr>
					<tr>
						<td class="form_label">员工姓名：</td>
						<td><input class="textbg1" id="tbe_name" name="tbe_name"  readonly="readonly" title="请选择员工"/></td>
						<td><font color="red">*</font></td>
						<td class="form_label">身份证号：</td>
						<td><input class="textbg1" id="tbe_idcard" name="tbe_idcard"  readonly="readonly"/></td>
						<td></td>
						<td class="form_label">配偶姓名：</td>
						<td><input class="textbg1" id="tbfi_spouse_name" name="tbfi_spouse_name" readonly="readonly"/></td>
						<td></td>
					</tr>
					<tr>
						<td class="form_label">性别：</td>
						<td><input class="textbg1" id="tbe_sex" name="tbe_sex" readonly="readonly"/></td>
	<!--							<td>-->
	<!--								<input class="textbg1" style="display: none;" id="sex" name="sex" readonly="readonly"/>-->
	<!--								<select id="tbe_sex" name="tbe_sex"   style=" width: 182px;">-->
	
	<!--								</select>-->
	<!--							</td>-->
						<td></td>
						<td class="form_label">子女数：</td>
						<td><input class="textbg1" id="tbfi_children_num" name="tbfi_children_num" readonly="readonly"/></td>
						<td></td>
						<td class="form_label">住址：</td>
						<td><input class="textbg1" id="tbe_address" name="tbe_address" readonly="readonly"/></td>
						<td></td>
					</tr>
					<tr>
						<td colspan="9" align="left">
							<div style="border-bottom: 1px solid #EBEBEB; font-weight:bold; height: 28px; line-height: 28px;margin: 0 0 5px;" >
								<img src="ligerUI/skins/icons/communication.gif"/>
								<span>发放明细</span>
							</div>
						</td>
					</tr>
					<tr>
						<td class="form_label">发放形式：</td>
						<td>
							<select id="tmapm_style" name="tmapm_style" style=" width: 182px;height: 25px;" >
								<option value="0">发放</option>
								<option value="1">领用</option>
							</select>
						</td>
						<td></td>
						<td class="form_label">用药时间：</td>
						<td><input id="tmapm_begin_time" name="tmapm_begin_time" value="<%=nowdate%>" onkeyup="this.value=formatdata(this.value);" /></td>
						<td></td>
						<td class="form_label">失败史：</td>
						<td align="left" id="tmapm_is_fail">
							<input style="margin-top: 2px; margin-left: 5px;" type="radio" name="tmapm_is_fail" value="1"  />有
							<input style="margin-top: 2px; margin-left: 5px;" type="radio" name="tmapm_is_fail" value="0" checked="checked"/>无
						</td>
						<td></td>
					</tr>
					<tr>
						<td class="form_label">发放月数：</td>
						<td>
							<select id="months" name="months" style=" width: 182px;height: 25px;" >
								<option value="1">1个月</option>
								<option value="2">2个月</option>
								<option value="3">3个月</option>
								<option value="4">4个月</option>
								<option value="5">5个月</option>
								<option value="6">6个月</option>
								<option value="7">7个月</option>
								<option value="8">8个月</option>
								<option value="9">9个月</option>
								<option value="10">10个月</option>
								<option value="11">11个月</option>
								<option value="12">12个月</option>
							</select>
						</td>
						<td></td>
						<td class="form_label">发放时间：</td>
						<td><input id="tmapm_time" name="tmapm_time" value="<%=nowdate %>"  onkeyup="this.value=formatdata(this.value);" /></td>
						<td></td>
						<td class="form_label">发放人：</td>
						<td><input  class="textbg1" id="tmapm_person" name="tmapm_person" value="<%=user.getUserrelName() %>"  readonly="readonly" /></td>
						<td></td>
					</tr>
					<tr>
						<td class="form_label">曾用药具：</td>
						<td>
						<textarea class="textbg3" id="tmapm_last_medicine" name="tmapm_last_medicine" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'" style="height: 40px;width: 182px;"></textarea>
						<td></td>
						<td class="form_label">失败原因：</td>
						<td>
						<textarea class="textbg3" id="tmapm_fail_reason" name="tmapm_fail_reason" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'" style="height: 40px;width: 182px;"></textarea>
						<td></td>
						<td class="form_label">用药理由：</td>
						<td>
						<textarea class="textbg3" id="tmapm_reason" name="tmapm_reason" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'" style="height: 40px;width: 182px;"></textarea>
						<td></td>
					</tr>
					<tr>
						<td colspan="9" align="left">
							<div style="border-bottom: 1px solid #EBEBEB; font-weight:bold;height: 28px; line-height: 28px;margin: 0 0 5px;" >
								<img src="ligerUI/skins/icons/communication.gif"/>
								<span>药具明细</span>
							</div>
						</td>
					</tr>
					<tr>
						<td class="form_label">药具种类：</td>
						<td>
							<select id="tmad_kind" name="tmad_kind"  style=" width: 182px;height: 25px;" onchange="selTamName(this.value,'mform');" >
								<%=tmadkind %>
							</select>
						<td></td>
						<td class="form_label">药具名称：</td>
						<td>
							<select id="tmad_id" name="tmad_id" style=" width: 182px;height: 25px;" onchange="tmaNameChange(this.value,'mform');" >
								<option value="">--请选择--</option>
							</select>
						<td><font color="red">*</font></td>
						<td class="form_label">数量：</td>
						<td><input  class="textbg1" id="tmapd_num" name="tmapd_num"  onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'" onchange="totalPrice();" onkeyup="totalPrice();"/></td>
						<td><font color="red">*</font></td>
					</tr>
					<tr>
						<td class="form_label">生产厂家：</td>
						<td><input class="textbg1" id="tmad_company_name" name="tmad_company_name"  readonly="readonly"/></td>
						<td></td>
						<td class="form_label">药品单位：</td>
						<td><input class="textbg1" id="tmad_unit" name="tmad_unit"  readonly="readonly"/></td>
						<td></td>
						
						<td class="form_label">药具库存：</td>
						<td><input class="textbg1" id="num" name="num"  readonly="readonly"/></td>
						<td></td>
					</tr>
					<tr>
						<td class="form_label">药品规格：</td>
						<td><input class="textbg1" id="tmad_spec" name="tmad_spec"  readonly="readonly"/></td>
						<td></td>
						<td class="form_label">单价：</td>
						<td><input class="textbg1" id="tmad_price" name="tmad_price"  readonly="readonly"/></td>
						<td></td>
						<td class="form_label">总金额：</td>
						<td><input class="textbg1" id="tmapd_zj" name="tmapd_zj"  readonly="readonly"/></td>
						<td></td>
					</tr>
					
				</table>
			</form>
		</div>
		<div id="empwin" style="display: none ;">
			<form id="query_pre">
				<input type="hidden" id="types" name="types" value="init"/>
				<table class="serTable">
					<tr>
						<td>
							机构：<select id="orgIds_query" name="orgIds_query" style=" width: 160px;">
							<option value="">全部</option>
							<%=user.getCurSubOrgOptions()%>
							</select>
						</td>
						<td>姓名：<input id="tbe_name_query" name="tbe_name_query" style=" width: 160px;"/></td>
						<td><input class="btn2" value="搜索" type="button" onclick="serchPer();" /></td>
						<td></td>
					</tr>
					<tr>
						<td>
							用工形式：<select id="tbe_employment_forms_query" name="tbe_employment_forms_query" style=" width: 160px;">
								<option value="0">全部</option>
								<%=tbe_employment_forms%>
							</select>
						</td>
						<td>身份证：<input id="tbe_idcard_query" name="tbe_idcard_query" style=" width: 160px;"/></td>
	<!--					<td><input class="btn2" value="高级搜索" type="button" onclick="serchPerAdv();" /></td>-->
						<td><input class="btn2" value="重置" type="button" onclick="serResetPer();" /></td>
					</tr>
				</table>
			</form>
			<div style="margin-right: 7px;">
				<div id="emp-grid"></div>
			</div>
		</div>
		<div id="tmawin" style="display: none ;">
			<form id="query_tma">
				<input type="hidden" id="types" name="types" value="init"/>
				<table class="serTable">
					<tr>
						<td>药具名称：<input id="name_query" name="name_query"/></td>
						<td>药具种类：<select id="type_query" name="type_query">
										<%=tmadkind %>
									</select></td>
						<td><input class="btn2" value="搜索" type="button" onclick="tmaserch1()" /></td>
						<td><input class="btn2" value="重置" type="button" onclick="tmaserReset()" /></td>
					</tr>
				</table>
			</form>
		</div>
		<div id="mdiv2" style="display: none;">
			<form id="mform2" name="mform2">
				<input type="hidden" id="tbe_id" name="tbe_id" value="" />
				<table class="form_table">
					<tr>
						<td colspan="9" align="left">
							<div style="border-bottom: 1px solid #EBEBEB; font-weight:bold;height: 28px; line-height: 28px;margin: 0 0 5px;" >
								<img src="ligerUI/skins/icons/communication.gif"/>
								<span>员工信息</span>
							</div>
						</td>
					</tr>
					<tr>
						<td class="form_label">员工姓名：</td>
						<td><input class="textbg1" id="tbe_name" name="tbe_name" disabled="disabled"/></td>
						<td></td>
						<td class="form_label">身份证号：</td>
						<td><input class="textbg1" id="tbe_idcard" name="tbe_idcard"  disabled="disabled"/></td>
						<td></td>
						<td class="form_label">配偶姓名：</td>
						<td><input class="textbg1" id="tbfi_spouse_name" name="tbfi_spouse_name" disabled="disabled"/></td>
						<td></td>
					</tr>
					<tr>
						<td class="form_label">性别：</td>
						<td><input class="textbg1" id="tbe_sex" name="tbe_sex" disabled="disabled"/></td>
						<td></td>
						<td class="form_label">子女数：</td>
						<td><input class="textbg1" id="tbfi_children_num" name="tbfi_children_num" disabled="disabled"/></td>
						<td></td>
						<td class="form_label">住址：</td>
						<td><input class="textbg1" id="tbe_address" name="tbe_address" disabled="disabled"/></td>
						<td></td>
					</tr>
					<tr>
						<td colspan="9" align="left">
							<div style="border-bottom: 1px solid #EBEBEB; font-weight:bold; height: 28px; line-height: 28px;margin: 0 0 5px;" >
								<img src="ligerUI/skins/icons/communication.gif"/>
								<span>发放明细</span>
							</div>
						</td>
					</tr>
					<tr>
						<td class="form_label">发放形式：</td>
						<td>
							<select id="tmapm_style" name="tmapm_style" style=" width: 182px;height: 25px;" disabled="disabled">
								<option value="0">发放</option>
								<option value="1">领用</option>
							</select>
						</td>
						<td></td>
						<td class="form_label">用药时间：</td>
						<td><input id="tmapm_begin_time" name="tmapm_begin_time" disabled="disabled" class="textbg1"/></td>
						<td></td>
						<td class="form_label">失败史：</td>
						<td align="left" id="tmapm_is_fail">
							<input style="margin-top: 2px; margin-left: 5px;" type="radio" name="tmapm_is_fail" value="1" disabled="disabled" />有
							<input style="margin-top: 2px; margin-left: 5px;" type="radio" name="tmapm_is_fail" value="0" checked="checked" disabled="disabled"/>无
						</td>
						<td></td>
					</tr>
					<tr>
						<td class="form_label">发放月数：</td>
						<td>
							<input class="textbg1" id="months" name="months" disabled="disabled" value="1个月" class="textbg1"/>
						</td>
						<td></td>
						<td class="form_label">发放时间：</td>
						<td><input id="tmapm_time" name="tmapm_time" disabled="disabled" class="textbg1"/></td>
						<td></td>
						<td class="form_label">发放人：</td>
						<td><input  class="textbg1" id="tmapm_person" name="tmapm_person" disabled="disabled"/></td>
						<td></td>
					</tr>
					<tr>
						<td class="form_label">曾用药具：</td>
						<td>
						<textarea class="textbg3" id="tmapm_last_medicine" name="tmapm_last_medicine" disabled="disabled" style="height: 40px;width: 182px;"></textarea>
						<td></td>
						<td class="form_label">失败原因：</td>
						<td>
						<textarea class="textbg3" id="tmapm_fail_reason" name="tmapm_fail_reason" disabled="disabled" style="height: 40px;width: 182px;"></textarea>
						<td></td>
						<td class="form_label">用药理由：</td>
						<td>
						<textarea class="textbg3" id="tmapm_reason" name="tmapm_reason" disabled="disabled" style="height: 40px;width: 182px;"></textarea>
						<td></td>
					</tr>
					<tr>
						<td colspan="9" align="left">
							<div style="border-bottom: 1px solid #EBEBEB; font-weight:bold;height: 28px; line-height: 28px;margin: 0 0 5px;" >
								<img src="ligerUI/skins/icons/communication.gif"/>
								<span>药具明细</span>
							</div>
						</td>
					</tr>
					<tr>
						<td class="form_label">药具种类：</td>
						<td>
							<select id="tmad_kind" name="tmad_kind"  style=" width: 182px;height: 25px;" disabled="disabled" >
								<%=tmadkind %>
							</select>
						<td></td>
						<td class="form_label">药具名称：</td>
						<td>
							<select id="tmad_id" name="tmad_id" style=" width: 182px;height: 25px;" disabled="disabled" >
								<option value="">--请选择--</option>
							</select>
						<td></td>
						<td class="form_label">数量：</td>
						<td><input  class="textbg1" id="tmapd_num" name="tmapd_num" disabled="disabled"/></td>
						<td></td>
					</tr>
					<tr>
						<td class="form_label">生产厂家：</td>
						<td><input class="textbg1" id="tmad_company_name" name="tmad_company_name" disabled="disabled"/></td>
						<td></td>
						<td class="form_label">药品单位：</td>
						<td><input class="textbg1" id="tmad_unit" name="tmad_unit"  disabled="disabled"/></td>
						<td></td>
						
						<td class="form_label">药具库存：</td>
						<td><input class="textbg1" id="num" name="num"  disabled="disabled"/></td>
						<td></td>
					</tr>
					<tr>
						<td class="form_label">药品规格：</td>
						<td><input class="textbg1" id="tmad_spec" name="tmad_spec"  disabled="disabled"/></td>
						<td></td>
						<td class="form_label">单价：</td>
						<td><input class="textbg1" id="tmad_price" name="tmad_price"  disabled="disabled"/></td>
						<td></td>
						<td class="form_label">总金额：</td>
						<td><input class="textbg1" id="tmapd_zj" name="tmapd_zj"  disabled="disabled"/></td>
						<td></td>
					</tr>
				</table>
			</form>
		</div>
	</body>
</html>
